package com.cn.unarmed.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.unarmed.activity.R;
import com.cn.unarmed.bean.DataHolder;

import java.util.List;

/**
 * 可选中的listView的适配器
 */
public class CheckListFrameAdapter extends BaseAdapter{

    private List<DataHolder> mList;
    private LayoutInflater mInflater;

    public CheckListFrameAdapter(Context context, List<DataHolder> list){
        this.mList = list;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.item_check_list_frame,null);
            holder = new ViewHolder();
            holder.title = (TextView)convertView.findViewById(R.id.title);
            holder.subtitle = (TextView)convertView.findViewById(R.id.subtitle);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(mList.get(position).titleStr);
        holder.subtitle.setText(mList.get(position).subTitleStr);
        return convertView;
    }

    class ViewHolder{
        TextView title;
        TextView subtitle;
    }
}
